package procsim;

public abstract class FlipFlop implements Element{
    protected Signal outSig, outSigPrev, outSigCompl, outSigResult;
    protected static boolean ticking = false;
    public FlipFlop(){
        outSig=new Signal(0, null);
        outSigPrev=new Signal(0, null);
    }
    public FlipFlop setResult(Signal sig){
        outSigResult=sig;
        return this;
    }
    public FlipFlop setResultNot(Signal sig){
        outSigCompl=sig;
        return this;
    }
    @Override
    public Signal result(){
        return outSigResult;
    }
    public Signal resultNot(){
        return outSigCompl;
    }
    protected void calculateComplement(){
        if(outSigCompl!=null) outSigCompl.set(outSig.negate());
    }
    @Override
    public String toString(){
        return ""+result();
    }
    public static void beginTicking(){
        ticking = true;
    }
    public static void endTicking(){
        ticking = false;
    }
}
